package com.thn.netty.chat.primitive;

import io.netty.buffer.ByteBuf;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.thn.netty.chat.codec.IMPB;

/**
 * Base class for commands.
 * @author Thierry Herrmann
 */
public class Command {
    private final PacketType pType;
    
    
    private final ByteBuf aIn;
    
    /**
     * Constructor.
     * @param aType command type. Used (among other things) to find the command's encoder/decoder.
     * @param aId command id. Used to reconcile requests with responses.
     */    
    public Command(PacketType aType, ByteBuf _aIn) {
    	pType = aType;
    	aIn=_aIn;  
    }
    
    public PacketType getType() {
        return pType;
    }
    
    public ByteBuf getMsgData() {
        return aIn;
    }
    
    
    /** {@inheritDoc} */
    @Override
    public String toString()
    {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
        .appendSuper(super.toString())
        .append("pType", pType)
        .toString();
    }
}
